<template>
  <div class="tab-bar-item" @click="itemClick">
    <!-- 一般不在插槽上设置样式，因为当插槽被替换时样式也被替换，样式可能失效，插槽外包一个div，在div身上设置可继承的样式 -->
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-active"></slot>
    </div>
    <div :style="activeStyle" :class="{active:isActive}">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>
<script>
export default {
  name: 'tabbar',
  props:{
    path:String,
    activeColor:{
      type:String,
      default:() => {
        return
      }
    }
  },
  data() {
    return {
      // isActive:true
    }
  },
  computed:{
    isActive(){
      return this.$route.path.indexOf(this.path) !==-1
    },
    activeStyle(){
      return this.isActive ? { color : this.activeColor } :{}
    }
  },
  methods:{
    itemClick(){
      this.$router.replace(this.path)
    }
  }
}
</script>
<style lang="scss" scoped>
.tab-bar-item {
  flex: 1; //均分
  text-align: center;
  height: 0.49rem; //一般是49px
  font-size: 0.14rem;

  img {
    width: 0.24rem;
    height: 0.24rem;
    margin-top: 0.03rem;
  }
  .active{
    color:red;
  }
}
</style>
